package com.example.huanhang.changzhouapp.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.huanhang.changzhouapp.R;
import com.example.huanhang.changzhouapp.bean.Pdf;
import com.gyf.barlibrary.ImmersionBar;

/**
 * @author lei
 * @desc 详情页面
 * @date 2018/8/24 0024 -- 下午 2:45.
 * 个人博客站: http://www.bestlei.top
 */
public class DetailsActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView mTvBh;
    private TextView mTvMc;
    private TextView mTvLx;
    private TextView mTvFl;
    private TextView mTvQcbm;
    private TextView mTvFs;
    private TextView mTvPzdate;
    private TextView mTvSsdate;
    private TextView mTvBb;
    private TextView mTvXg;
    private TextView mTvBz;
    private TextView mTvWj;
    private Button btnPdf;
    private String mPath;
    private AppCompatImageView mIvBack;
    private AppCompatTextView mTvTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_details);
        initView();
        initdata();
    }


    private void initView() {
        mTvBh = (TextView) findViewById(R.id.tv_bh);
        mTvMc = (TextView) findViewById(R.id.tv_mc);
        mTvLx = (TextView) findViewById(R.id.tv_lx);
        mTvFl = (TextView) findViewById(R.id.tv_fl);
        mTvQcbm = (TextView) findViewById(R.id.tv_qcbm);
        mTvFs = (TextView) findViewById(R.id.tv_fs);
        mTvPzdate = (TextView) findViewById(R.id.tv_pzdate);
        mTvSsdate = (TextView) findViewById(R.id.tv_ssdate);
        mTvBb = (TextView) findViewById(R.id.tv_bb);
        mTvXg = (TextView) findViewById(R.id.tv_xg);
        mTvBz = (TextView) findViewById(R.id.tv_bz);
        mTvWj = (TextView) findViewById(R.id.tv_wj);
        btnPdf = (Button) findViewById(R.id.btn_pdf);
        btnPdf.setOnClickListener(this);
        mIvBack = (AppCompatImageView) findViewById(R.id.iv_back);
        mIvBack.setOnClickListener(this);
        mTvTitle = (AppCompatTextView) findViewById(R.id.tv_title);
        mTvTitle.setText("查看详情");
        ImmersionBar.with(this).statusBarColor(R.color.title).init();
    }

    private void initdata() {
        Bundle bundle = getIntent().getExtras();
        Pdf pdfValues = bundle.getParcelable("pdfValues");
        String name = pdfValues.getName();
        String fenlei = pdfValues.getFenlei();
        String number = pdfValues.getNumber();
        String pzDate = pdfValues.getPzDate();
        String shiSDate = pdfValues.getShiSDate();
        String style = pdfValues.getStyle();
        String version = pdfValues.getVersion();
        String updateNum = pdfValues.getUpdateNum();
        mPath = pdfValues.getPdfPath();
        if (TextUtils.isEmpty(name)) {
            mTvMc.setText("暂无数据");
        } else {
            mTvMc.setText(name);
        }
        if (TextUtils.isEmpty(fenlei)) {
            mTvFl.setText("暂无数据");
        } else {
            mTvFl.setText(fenlei);
        }
        if (TextUtils.isEmpty(number)) {
            mTvBh.setText("暂无数据");
        } else {
            mTvBh.setText(number);
        }
        if (TextUtils.isEmpty(pzDate)) {
            mTvPzdate.setText("暂无数据");
        } else {
            mTvPzdate.setText(pzDate);
        }
        if (TextUtils.isEmpty(shiSDate)) {
            mTvSsdate.setText("暂无数据");
        } else {
            mTvSsdate.setText(shiSDate);
        }
        if (TextUtils.isEmpty(style)) {
            mTvLx.setText("暂无数据");
        } else {
            mTvLx.setText(style);
        }
        if (TextUtils.isEmpty(version)) {
            mTvBb.setText("暂无数据");
        } else {
            mTvBb.setText(version);
        }
        if (TextUtils.isEmpty(updateNum)) {
            mTvXg.setText("暂无数据");
        } else {
            mTvXg.setText(updateNum);
        }
        if (TextUtils.isEmpty(mPath)) {
            mTvWj.setText("暂无数据");
        } else {
            mTvWj.setText("点击右侧按钮查看pdf");
        }
        mTvQcbm.setText("暂无数据");
        mTvBz.setText("暂无数据");
        mTvFs.setText("暂无数据");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_pdf:
                if (Build.VERSION.SDK_INT >= 21) {
                    Intent intent = new Intent(this, ShowPdfActivity.class);
                    intent.putExtra("pdfPath", mPath);
                    startActivity(intent);

                } else {
                    Intent intent=new Intent(this,ShowPdf2Activity.class);
                    intent.putExtra("pdfPath", mPath);
                    startActivity(intent);
                }
                break;
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
